import Vue from 'vue'
import Vuex from 'vuex'

import VuexPersistence from 'vuex-persist'

Vue.use(Vuex)
// 实例化我们的插件
const vuexLocal = new VuexPersistence({
  storage: window.sessionStorage
})

export default new Vuex.Store({
  plugins: [vuexLocal.plugin],
  state: {
    token: '',
    defaultActiveId: '',
    userInfo: {
      // 查询的参数
      query: '',
      // 查询的当前页码
      pagenum: 1,
      // 每页的条数
      pagesize: 2
    }
  },
  getters: {
    getToken: state => state.token,
    getDefaultActiveId: state => state.defaultActiveId,
    getUserInfo: state => state.userInfo
  },
  mutations: {
    SAVE_TOKEN (state, data) {
      state.token = data
    },
    SAVE_DefaultActive_DefaultActive_ID (state, data) {
      state.defaultActiveId = data
    },
    CLEAR_TOKEN (state) {
      state.token = ''
      state.defaultActiveId = ''
    },
    SAVE_USER_INFO (state, data) {
      state.userInfo = data
    }
  },
  actions: {

  }
})
